package com.tang.managementdemo.exception;

import com.tang.managementdemo.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    // 处理自定义异常
    // 处理部门不为空的异常
    @ExceptionHandler(DepartmentNotEmptyException.class)
    public Result handleDepartmentNotEmptyException(DepartmentNotEmptyException e) {
        return Result.error(e.getMessage());
    }

    // 处理登录不存在的异常
    @ExceptionHandler(LoginNotExistException.class)
    public Result handleLoginNotExistException(LoginNotExistException e) {
        return Result.error(e.getMessage());
    }

    //处理异常
    @ExceptionHandler
    public Result handleException(Exception e) { //e为异常信息
        e.printStackTrace(); //打印异常信息
        return Result.error(e.toString());
    }

}
